package demo.xlj.yuyi.studentapp.myView;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import demo.xlj.yuyi.studentapp.R;

/**
 * 作者：项路俊 on 2018/3/7 0007
 * 邮箱：ThanksForCode@gmail.com
 * 介绍：演示带有方框的TextView
 */

public class RectTextView extends android.support.v7.widget.AppCompatTextView {

    public RectTextView(Context context) {
        super(context);
    }

    public RectTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RectTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    private Paint mPaint = new Paint();

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        String text = (String) getText();
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(getResources().getColor(R.color.colorAccent));
        Rect rect = new Rect(0, 0, getWidth(), getHeight());
        canvas.drawRect(rect, mPaint);

    }
}
